package morning.cat.springdatademo.repository;

import morning.cat.springdatademo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;


public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

    User findByName(String name);

    @Query("select id,name,age from t_user where name=:name and age=:age")
    User getByGq(@Param("name") String name, @Param("age") Integer age);

    @Query("select id,name,age from t_user where name=?1 and age=?2")
    User getByGq2(String name, Integer age);

    @Query("select id,name,age from t_user where name like %:name%")
    User getLikeGq(@Param("name") String name);

    List<User> findAllByName(String name);
}
